<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui"
	xmlns:c="http://java.sun.com/jsp/jstl/core" 
	xmlns:sec="http://www.springframework.org/security/tags" >

<f:view contentType="text/html">

	<h:head>
		<f:facet name="first">
			<meta content='text/html; charset=UTF-8' http-equiv="Content-Type" />
			<title>Sistema UTI Neonatal</title>
		</f:facet>

		<link type="text/css" rel="stylesheet"
			href="#{request.contextPath}/css/default.css" />
		<link type="text/css" rel="stylesheet"
			href="#{request.contextPath}/css/syntaxhighlighter/syntaxhighlighter.css" />
		
		<f:metadata>
			<f:event type="preRenderView" listener="#{ringController.getRingController}" />
		</f:metadata>
		
		<ui:insert name="head"></ui:insert>

		<script type="text/javascript">
			$(function() {
				$('.sidebar a').hover(function() {
					$(this).toggleClass('ui-state-hover');
				})
			});
		</script>
	</h:head>

	<h:body>

		<p:layout fullPage="true">

			<p:layoutUnit position="north" size="100" closable="false"
				collapsible="true">
					<h:panelGrid columns="2" cellpadding="5" style="margin-left:40px;">
						<p:graphicImage value="#{request.contextPath}/../images/logo.png" />
						<p:graphicImage value="#{request.contextPath}/../images/logoTexto.png" />
					</h:panelGrid>
			</p:layoutUnit>

			<p:layoutUnit position="south" size="20" collapsible="true">
				<center>© 2012 - Desenvolvido por Epitácio Miguel e Rafael
					Vilaça</center>
			</p:layoutUnit>

			<p:layoutUnit position="west" size="150" header="Menu"
				resizable="true" collapsible="true" effect="drop">
				<h:form>
					<p:menu type="sliding" style="width:130px; height: 300px;" backLabel="Voltar">
						<p:menuitem value="Inicio" url="/ui/formLeitos.xhtml" />
						<p:submenu label="Gerenciar" rendered="#{sec:areAllGranted('ROLE_ADMIN')}" >
							<p:menuitem value="Perfis" url="/ui/formPerfis.xhtml" />
							<p:menuitem value="Usuários" url="/ui/formUsuarios.xhtml" />
							<p:menuitem value="Tipo de Sintomas" url="/ui/formTipoSintomas.xhtml" />
							<p:menuitem value="Sintomas" url="/ui/formSintomas.xhtml" />
							<p:menuitem value="Diagnósticos" url="/ui/formDiagnosticos.xhtml" />
							<p:menuitem value="Intervenções" url="/ui/formIntervencoes.xhtml" />
						</p:submenu>
						<p:menuitem value="Histórico de Enfermagem" url="/ui/formPesqPacientes.xhtml" />
						<p:menuitem value="Sair" onclick="location.href='#{facesContext.externalContext.requestContextPath}/j_spring_security_logout'" />
					</p:menu>
				</h:form>
			</p:layoutUnit>

			<p:layoutUnit position="east" size="200" header="Dados Pessoais"
				resizable="true" collapsible="true" effect="drop">
				<f:verbatim>
					<br />
				</f:verbatim>
				<h:outputText
					value="Bem vindo!" />
				<f:verbatim>
					<br />
					<br />
				</f:verbatim>
				<h:outputText
					value="Nome: #{usuarioSessaoController.usuarioSessao.nome}" />
				<f:verbatim>
					<br />
					<br />
				</f:verbatim>
				<h:outputText
					value="Perfil: #{usuarioSessaoController.usuarioSessao.perfil.descricao}" />
				<f:verbatim>
					<br />
					<br />
				</f:verbatim>
				<h:outputText
						value="COREN: #{usuarioSessaoController.usuarioSessao.coren}" rendered="#{sec:areAllGranted('ROLE_ENF')}"/>
				<h:outputText
						value="COREN: #{usuarioSessaoController.usuarioSessao.coren}" rendered="#{sec:areAllGranted('ROLE_TEC')}"/>		
					<f:verbatim>
						<br />
						<br />
					</f:verbatim>
			</p:layoutUnit>

			<p:layoutUnit id="layoutUnitPri" position="center" resizable="true"
				collapsible="true" effect="drop" size="500">

				<ui:insert name="content">

					<center>
						<h:form id="form">

							<p:panel style="height:95%;width:95%"
								header="HOSPITAL UNIVERSITÁRIO LAURO WANDERLEY - UNIDADE DE TERAPIA INTENSIVA NEONATAL">

								<p:panel id="panelLeitos" style="height:95%;width:95%"
									header="Gerenciamento de Leitos" widgetVar="infoLeito"
									visible="true" effect="fade" closable="true" closeSpeed="0">

									<c:if test="#{ringController.vazio == true}">
										<f:verbatim>
											<br />
										</f:verbatim>
										<h:outputText
											value="Os Leitos estão desocupados!" rendered="#{sec:areAllGranted('ROLE_TEC')}"/>
									</c:if>
								
									<c:forEach items="#{ringController.leitos}" var="leito">

										<c:choose>
											<c:when test="#{(leito.id &lt; 4)}">
												<c:choose>
													<c:when test="#{(leito.paciente != null)}">
														<p:commandButton id="carBtn#{leito.id}"
															value="LEITO #{leito.id}"
															style="margin:60px;width:100px;height:50px;">
														</p:commandButton>
													</c:when>
													<c:otherwise>
														<p:commandButton id="carBtn#{leito.id}"
															value="LEITO #{leito.id}"
															style="margin:60px;width:100px;height:50px;background:none;color:black;"
															oncomplete="infoLeito.close(); "
															rendered="#{sec:areAllGranted('ROLE_ADMIN')}">
															<f:setPropertyActionListener value="#{leito.id}"
																target="#{ringController.selectedLeito}" />
														</p:commandButton>
														<p:commandButton id="carBtn1#{leito.id}"
															value="LEITO #{leito.id}"
															style="margin:60px;width:100px;height:50px;background:none;color:black;"
															oncomplete="infoLeito.close(); "
															rendered="#{sec:areAllGranted('ROLE_ENF')}">
															<f:setPropertyActionListener value="#{leito.id}"
																target="#{ringController.selectedLeito}" />
														</p:commandButton>
													</c:otherwise>
												</c:choose>

												<c:if test="#{(leito.paciente != null)}">
													<p:overlayPanel id="carPanel#{leito.id}"
														for="carBtn#{leito.id}" hideEffect="fade">

														<h:outputText
															value="Leito ocupado por #{leito.paciente.nome} 
												desde  #{leito.paciente.data_admissao} #{leito.paciente.hora_admissao}" />

														<br />

														<p:commandButton id="ver#{leito.id}"
															value="Verificar dados"
															oncomplete="carPanel#{leito.id}.hide()">
															<f:setPropertyActionListener value="#{leito.id}"
																target="#{ringController.selectedLeito}" />
														</p:commandButton>
														<p:commandButton id="des#{leito.id}"
															value="Desocupar Leito"
															oncomplete="carPanel#{leito.id}.hide()"
															rendered="#{sec:areAllGranted('ROLE_ENF')}">
															<f:setPropertyActionListener value="#{leito.id}"
																target="#{ringController.desocupiedLeito}" />
														</p:commandButton>
														<p:commandButton id="des1#{leito.id}"
															value="Desocupar Leito"
															oncomplete="carPanel#{leito.id}.hide()"
															rendered="#{sec:areAllGranted('ROLE_ADMIN')}">
															<f:setPropertyActionListener value="#{leito.id}"
																target="#{ringController.desocupiedLeito}" />
														</p:commandButton>

													</p:overlayPanel>
												</c:if>


												<c:if test="#{(leito.id == 3)}">
													<f:verbatim>
														<br />
													</f:verbatim>
												</c:if>
											</c:when>
											<c:otherwise>
												<c:choose>
													<c:when test="#{(leito.paciente != null)}">
														<p:commandButton id="carBtn#{leito.id}"
															value="LEITO #{leito.id}"
															style="margin:60px;width:100px;height:50px;">
														</p:commandButton>
													</c:when>
													<c:otherwise>
														<p:commandButton id="carBtn#{leito.id}"
															value="LEITO #{leito.id}"
															style="margin:60px;width:100px;height:50px;background:none;color:black;"
															rendered="#{sec:areAllGranted('ROLE_ADMIN')}">
															<f:setPropertyActionListener value="#{leito.id}"
																target="#{ringController.selectedLeito}" />
														</p:commandButton>
														<p:commandButton id="carBtn2#{leito.id}"
															value="LEITO #{leito.id}"
															style="margin:60px;width:100px;height:50px;background:none;color:black;"
															rendered="#{sec:areAllGranted('ROLE_ENF')}">
															<f:setPropertyActionListener value="#{leito.id}"
																target="#{ringController.selectedLeito}" />
														</p:commandButton>
													</c:otherwise>
												</c:choose>




												<c:if test="#{(leito.paciente != null)}">
													<p:overlayPanel id="carPanel#{leito.id}"
														for="carBtn#{leito.id}" hideEffect="fade">

														<h:outputText
															value="Leito ocupado por #{leito.paciente.nome} 
												desde  #{leito.paciente.data_admissao} #{leito.paciente.hora_admissao}" />

														<br />

														<p:commandButton id="ver#{leito.id}"
															value="Verificar dados"
															oncomplete="carPanel#{leito.id}.hide()">
															<f:setPropertyActionListener value="#{leito.id}"
																target="#{ringController.selectedLeito}" />
														</p:commandButton>
														<p:commandButton id="des#{leito.id}"
															value="Desocupar Leito"
															oncomplete="carPanel#{leito.id}.hide()"
															rendered="#{sec:areAllGranted('ROLE_ENF')}">
															<f:setPropertyActionListener value="#{leito.id}"
																target="#{ringController.desocupiedLeito}" />
														</p:commandButton>
														<p:commandButton id="des2#{leito.id}"
															value="Desocupar Leito"
															oncomplete="carPanel#{leito.id}.hide()"
															rendered="#{sec:areAllGranted('ROLE_ADMIN')}">
															<f:setPropertyActionListener value="#{leito.id}"
																target="#{ringController.desocupiedLeito}" />
														</p:commandButton>

													</p:overlayPanel>
												</c:if>


											</c:otherwise>
										</c:choose>

									</c:forEach>


								</p:panel>

							</p:panel>

						</h:form>

					</center>
				</ui:insert>

			</p:layoutUnit>

		</p:layout>
	</h:body>
</f:view>
</html>
